﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Diagnostics;


namespace GuideBoard.DLL
{
    public class ConfigDSOFramer
    {
        public ConfigDSOFramer() { }
        ~ConfigDSOFramer() { }

        public static bool Regsvr32(string RegistFilePath, string RegistFile, ref string msg)
        {
            bool result = false;
            string sPath = RegistFilePath + RegistFile;

            // C盘下已经存在dsoframer.ocx
            if (System.IO.File.Exists(sPath))
            {
                ProcessStartInfo psi = new ProcessStartInfo("regsvr32", "/s " + sPath);
                Process.Start(psi);
                msg = sPath + "已经存在！";
                result = true;
            }
            else
            {
                // C盘下不存在dsoframer.ocx 则先检查debug下存不存在，
                // 如果存在则复制到C盘目录下，如果不存在，则提示用户缺少必要文件！
                if (System.IO.File.Exists(System.IO.Directory.GetCurrentDirectory() + @"\" + RegistFile))
                {
                    // 复制ocx文件到"C:\WINDOWS\system32\"下
                    string sourceAddress = System.IO.Directory.GetCurrentDirectory() + @"\" + RegistFile;
                    string destinationAddress = sPath;
                    System.IO.File.Copy(sourceAddress, destinationAddress);
                    ProcessStartInfo psi = new ProcessStartInfo("regsvr32", "/s " + destinationAddress);
                    Process.Start(psi);
                    msg = sPath + "文件注册成功！";
                    result = true;
                }
                else
                {
                    msg = "缺少" + RegistFile + "文件，请先保证debug下有这个文件。";
                    result = false;
                }
            }

            return result;

        }
    }
}
